package com.yangluyao.jsr303.hibernate.validator.service.impl;

import com.yangluyao.jsr303.hibernate.validator.model.User;
import com.yangluyao.jsr303.hibernate.validator.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YLY
 * @ClassName UserServiceImpl
 * @Date 2020/7/29
 * @Version 1.0.2
 */
@Service
public class UserServiceImpl implements IUserService {

    private static Map<Long, User> userMap = new HashMap<>();

    static {
        userMap.put(1L,new User(1L,"yangluyao1",10));
        userMap.put(2L,new User(2L,"yangluyao2",20));
        userMap.put(3L,new User(3L,"yangluyao3",30));
    }


    @Override
    public String findUserName(Long id) {
        Integer integer = null;
        integer.equals("");
        return userMap.get(id).getName();
    }

    @Override
    public List<User> findUsers() {
        List<User> list = new ArrayList<>();
        userMap.forEach((k,v)->{
            list.add(v);
        });
        return list;
    }

    @Override
    public User findUserById(Long id) {
        return userMap.get(id);
    }

    @Override
    public User saveUser(User user) {
        return userMap.put(user.getId(), user);
    }
}
